package cn.edu.pku.ssm.dao;

import java.sql.*;

public class UserDAO {
	
		public static void main(String[] args) {
			UserDAO.getAge("Tom");
		}
		

		public static int getAge(String name){
			try {
				int age=0;
				DbUtil.init();
				Connection conn 
					= DbUtil.getConnection();
				String sql = "select age from users2 where name = ?";
				
				PreparedStatement preStmt
					= conn.prepareStatement(sql);
				preStmt.setString(1, name);
				ResultSet rs = preStmt.executeQuery();
				while (rs.next()) {
					age = rs.getInt(1);
					
					System.out.println("age+age");
				}
				preStmt.close();
				
				DbUtil.close(conn);
				return age;
			} catch (SQLException e) {
				e.printStackTrace();
				return 0;
				
			}
		}
	

}
